package com.example.demo.service.impl;



import com.example.demo.mapper.OrderDetailMapper;
import com.example.demo.pojo.OrderDetail;
import com.example.demo.pojo.OrderDetailDTO;
import com.example.demo.service.OrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class OrderDetailsServiceImpl implements OrderDetailsService{

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Override
    public boolean addOrderDetail(OrderDetailDTO dto) {
        OrderDetail entity = new OrderDetail();
        entity.setOrderId(dto.getOrderId());
        entity.setProductId(dto.getProductId());
        entity.setQuantity(dto.getQuantity());
        entity.setPrice(dto.getPrice());
        entity.setUserId(dto.getUserId());
        entity.setCreatedAt(LocalDateTime.now()); // 系统生成时间

        return orderDetailMapper.insertOrderDetail(entity) > 0;
    }
}
